#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 10;

int n, m;

struct node
{
	int p, a;
}a[N];

bool cmp(node& n1, node& n2)
{
	return n1.p < n2.p;
}

int main()
{
	cin >> n >> m;
	for(int i = 1;i <= m;i ++) cin >> a[i].p >> a[i].a;
	sort(a + 1, a + 1 + m, cmp);
	int ans = 0, sum = 0;
	for(int i = 1;i <= m;i ++)
	{
		ans += a[i].p * min(a[i].a, n - sum);
		sum += min(a[i].a, n - sum);
	}
	cout << ans << endl;
	return 0;
}